{include file="public/header" /}
<link rel="stylesheet" href="/static/admin/addons/builderPlus/css/base.css" media="all">
<style>
    .layui-icon-file {
        display: none;
    }
</style>
<body>
<div class="layui-fluid layui-anim layui-anim-downbit">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form " id="form" action='{:url("role/give",["id"=>$Request.param.id])}'>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item ">
                            <label class="layui-form-label">权限：</label>
                            <div class="layui-input-block">
                                <div id="rules"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div style="clear: both;height: 300px;"></div>
<div class="layui-footer" style="left: 0;">
    <button class="layui-btn builderSubmit" lay-filter="saveRole" lay-submit formObj="#form">
        保存
    </button>
</div>
</body>
{include file="public/footer" /}
<script>
    layui.use(['tree', 'form', 'jquery', 'methods', 'notify'], function () {
        var notify = layui.notify, tree = layui.tree, f = layui.form, methods = layui.methods;
        notify.init();
        tree.render({
            elem: '#rules',
            id: 'rules',
            data: JSON.parse('<?php echo json_encode($list);?>'),
            showCheckbox: true,
            // showLine: false
        });
        f.on('submit(saveRole)', function (data) {
            var list = tree.getChecked('rules'), ids = [];
            if (list.length > 0) {
                list.forEach(function (v, i) {
                    ids.push(v.id);
                    v.children.forEach(function (v1, i1) {
                        ids.push(v1.id);
                        v1.children.forEach(function (v2, i2) {
                            ids.push(v2.id);
                        });
                    });
                });
            }
            methods.fetchPostThrottle('{:url("role/give")}', {rules: ids, id: '{$Request.param.id}'}, function (data) {
                notify.success(data.msg, 1000, function () {
                    parent.layui.layer.closeAll();
                    parent.layui.table.reload('builderTable', {
                        page: {
                            curr: parent.layui.jquery(".layui-laypage-em").next().text()
                        },
                    });
                });
            });
        });
    });
</script>
</html>